package com.chaihu.admin.service.impl.menu;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chaihu.admin.dao.MenuServiceDao;
import com.chaihu.bean.dto.admin.MenuDto;
import com.chaihu.bean.in.admin.menu.SaveMenuIn;
import com.chaihu.bean.result.ResponseResult;
import com.chaihu.core.factory.GenerateCodeFactory;
import com.chaihu.intf.admin.menu.SaveMenuService;
import com.chaihu.intf.icommon.BaseService;
import com.chaihu.utils.util.BeanConvertUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
public class SaveMenuServiceImpl extends BaseService<ResponseResult<Void>, SaveMenuIn> implements SaveMenuService {
    @Autowired
    private MenuServiceDao menuServiceDao;

    @Override
    public ResponseResult<Void> checkHandle(ResponseResult<Void> responseResult, SaveMenuIn in) {
        return responseResult;
    }

    @Override
    public ResponseResult<Void> doHandle(ResponseResult<Void> responseResult, SaveMenuIn in) {
        if(StringUtils.isEmpty(in.getmId())){
            in.setgId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.MENU));
        }
        int i = menuServiceDao.insert(in);
        return responseResult;
    }

    @Override
    public ResponseResult<Void> respHandle(ResponseResult<Void> responseResult, SaveMenuIn in) {
        return responseResult;
    }

    @Override
    public ResponseResult<Void> saveMenu(SaveMenuIn in) {
        ResponseResult<Void> result = new ResponseResult<>();
        return this.mainHandle(result, in);
    }
}
